]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
autorun: prefer Safe Removal over eject/unmount if possible
authorCosimo Cecchi <cosimoc@gnome.org>
Thu, 23 Jun 2011 14:08:17 +0000 (10:08 -0400)
committerCosimo Cecchi <cosimoc@gnome.org>
Wed, 13 Jul 2011 18:39:36 +0000 (14:39 -0400)
Basically do what NautilusPlacesSidebar does with the drive/volume/mount
eject/unmount/stop priorities.

We follow this pattern:
- always prefer Safely Remove if available (i.e. drive.stop())
- fallback to ejecting the mount/volume/drive if that's not possible
- finally, fallback to unmounting the mount if even eject is not
  available

This also means we don't care about the distinction between
Stop/Eject/Unmount at this level. Disk Utility (or Nautilus) are
available for those who want that degree of control, but the common case
here should do the most useful action without presenting the choice.

https://bugzilla.gnome.org/show_bug.cgi?id=653520

js/ui/autorunManager.js

index 368467c229db549bef8b8719cb1b26cd0c244468..5ba4868da5bd456811942a2a7a38eaef36593269 100644 (file)
@@ -205,20 +205,35 @@ AutorunManager.prototype = {
     ejectMount: function(mount) {
         let mountOp = new ShellMountOperation.ShellMountOperation(mount);
 
-        if (mount.can_eject())
-            mount.eject_with_operation(0, mountOp.mountOp, null,
-                                       Lang.bind(this, this._onMountEject));
-        else
-            mount.unmount_with_operation(0, mountOp.mountOp, null,
-                                         Lang.bind(this, this._onMountEject));
+        // first, see if we have a drive
+        let drive = mount.get_drive();
+        let volume = mount.get_volume();
+
+        if (drive &&
+            drive.get_start_stop_type() == Gio.DriveStartStopType.SHUTDOWN &&
+            drive.can_stop()) {
+            drive.stop(0, mountOp.mountOp, null,
+                       Lang.bind(this, this._onStop));
+        } else {
+            if (mount.can_eject()) {
+                mount.eject_with_operation(0, mountOp.mountOp, null,
+                                           Lang.bind(this, this._onEject));
+            } else if (volume && volume.can_eject()) {
+                volume.eject_with_operation(0, mountOp.mountOp, null,
+                                            Lang.bind(this, this._onEject));
+            } else if (drive && drive.can_eject()) {
+                drive.eject_with_operation(0, mountOp.mountOp, null,
+                                           Lang.bind(this, this._onEject));
+            } else if (mount.can_unmount()) {
+                mount.unmount_with_operation(0, mountOp.mountOp, null,
+                                             Lang.bind(this, this._onUnmount));
+            }
+        }
     },
 
-    _onMountEject: function(mount, res) {
+    _onUnmount: function(mount, res) {
         try {
-            if (mount.can_eject())
-                mount.eject_with_operation_finish(res);
-            else
-                mount.unmount_with_operation_finish(res);
+            mount.unmount_with_operation_finish(res);
         } catch (e) {
             // FIXME: we need to ignore G_IO_ERROR_FAILED_HANDLED errors here
             // but we can't access the error code from JS.
@@ -227,6 +242,30 @@ AutorunManager.prototype = {
                 + ': ' + e.toString());
         }
     },
+
+    _onEject: function(source, res) {
+        try {
+            source.eject_with_operation_finish(res);
+        } catch (e) {
+            // FIXME: we need to ignore G_IO_ERROR_FAILED_HANDLED errors here
+            // but we can't access the error code from JS.
+            // See https://bugzilla.gnome.org/show_bug.cgi?id=591480
+            log('Unable to eject the drive ' + source.get_name() 
+                + ': ' + e.toString());
+        }
+    },
+
+    _onStop: function(drive, res) {
+        try {
+            drive.stop_finish(res);
+        } catch (e) {
+            // FIXME: we need to ignore G_IO_ERROR_FAILED_HANDLED errors here
+            // but we can't access the error code from JS.
+            // See https://bugzilla.gnome.org/show_bug.cgi?id=591480
+            log('Unable to stop the drive ' + drive.get_name() 
+                + ': ' + e.toString());
+        }
+    },
 }
 
 function AutorunResidentSource() {